<?php

/**
 * @property-read int $ID
 * @property-read string $Name
 * @property string $Image
 * @property-read int $Price
 * @property int $Amount
 * @property-read int $TotalCost
 */
class ProductItem
{
    /** @var int */
    protected $id;

    /** @var string */
    protected $name;

    /** @var string */
    protected $image;

    /** @var int */
    protected $price;

    /** @var int */
    protected $amount;

    /**
     * @param int $id
     * @param string $name
     * @param string $image
     * @param int $price
     * @param int $amount
     * @return ProductItem
     */
    public function __construct($id, $name, $image, $price, $amount)
    {
        $this->id = $id;
        $this->name = $name;
        $this->image = $image;
        $this->price = $price;
        $this->amount = $amount;
    }

    /**
     * @param $name
     * @return mixed
     * @throws Exception
     */
    public function __get($name)
    {
        switch ($name) {
            case 'ID':
                return $this->id;
            case 'Name':
                return $this->name;
            case 'Image':
                return $this->image;
            case 'Price':
                return $this->price;
            case 'Amount':
                return $this->amount;
            case 'TotalCost':
                return $this->price * $this->amount;
            default:
                throw new Exception("cannot get $name property");
        }
    }

    /**
     * @param string $name
     * @param mixed $value
     * @return void
     * @throws Exception
     */
    public function __set($name, $value)
    {
        switch ($name) {
            case 'Image':
                $this->image = $value;
                break;
            case 'Amount':
                $this->amount = $value;
                break;
            default:
                throw new Exception("cannot set $name property");
        }
    }
}
